package com.example.common;

import org.apache.ibatis.exceptions.TooManyResultsException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.FileNotFoundException;


@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = MethodArgumentNotValidException.class)
    public R handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
        return R.error("异常失败");
    }

    // 其他异常处理方法 TooManyResultsException
    @ExceptionHandler(value = TooManyResultsException.class)
    public R erro(TooManyResultsException e) {

        return R.error("自定义异常！查到多条类似数据！");
    }

    // 文件路径未定义
//    @ExceptionHandler(value = FileNotFoundException.class)
//    public R erro2(FileNotFoundException e) {
//
//        return R.error("文件路径未定义！请给图片重定义！");
//    }
}

